'use strict';

module.exports = function ($scope, growl, $cookieStore) {

    $scope.addSpecialWarnMessage = function() {
        growl.addInfoMessage("This adds a warn message");
    } 

    //$scope.addSpecialWarnMessage();

  $scope.statutConnexion = "deconnecte";

  $scope.connexion = function (email, password) {
   
      var credentials = {
          username: this.username,
          token: this.token
      };

      var success = function (data) {
          var token = data.token;
          api.init(token);
          $cookieStore.put('token', token);
          $scope.statutConnexion = "connecte";
          $location.path('/');
      };

      var error = function () {
          // TODO: apply user notification here..
      };

      authorization.login(credentials).success(success).error(error);

  };


  $scope.deconnexion = function () {
    $scope.statutConnexion = "deconnecte";
  };
};